package com.wzy.controller;

import java.sql.*;

/**
 * @Auther: wzy
 * @Date: 2021/11/26/20:57
 * @Description:
 */
public class TestConnection {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/juc?useUnicode=true&serverTimezone=GMT%2B8&useSSL=false", "root", "wangyun1");
        Statement stat = conn.createStatement();
        ResultSet resultSet = null;
        String queryTable = "select * from information_schema.tables where table_name ='user' and TABLE_SCHEMA = 'juc'";
        ResultSet resultSet1 = stat.executeQuery(queryTable);
        if (resultSet1.next()) {
            String deleteSql = "drop table user";
            stat.execute(deleteSql);
        }
        String sql = "CREATE TABLE user (\n" +
                "name int(10),\n" +
                "salary bigint(50)\n" +
                ")";
        stat.execute(sql);
        String sql1 = "INSERT INTO user(name,salary)\n" +
                "VALUES \n" +
                "(10000,500),\n" +
                "(10001,1000)";
        boolean execute1 = stat.execute(sql1);
        stat.close();
        conn.close();
    }
}
